



AddReplicableComponent("obrsword_power")
AddPlayerPostInit(function(inst)
    inst:AddTag("__obrsword_power")
    if TheWorld.ismastersim then --组件部分只需要服务端添加
        inst:RemoveTag("__obrsword_power")
        inst:PrereplicateComponent("obrsword_power")

       inst:AddComponent("obrsword_power")
        local ex = inst.components.obrsword_power.extrapower + 100
        inst.components.obrsword_power:SetMax(ex)
      inst.components.obrsword_power:start_obrsword_power(inst)
       -- inst.components.obrsword_power:DoDelta(0)
    end
end)
-- 界面部分

local obrsword_powerBadge = require("widgets/obrsword_powerbadge")
local function Add_obrsword_power(self)

    self.obrsword_power = self:AddChild(obrsword_powerBadge(self.owner))
 
    self.owner:DoTaskInTime(0.5, function()
      --[[ local x1, y1, z1 = self.stomach:GetPosition():Get()
        local x2, y2, z2 = self.brain:GetPosition():Get()
        local x3, y3, z3 = self.heart:GetPosition():Get()
        print(x1, y1, z1)
        if y2 == y1 or y2 == y3 then -- 开了三维mod
            self.obrsword_power:SetPosition(self.stomach:GetPosition() + Vector3(x1 - x2, 0, 0))
        else
            self.obrsword_power:SetPosition(self.stomach:GetPosition() + Vector3(x1 - x3, 0, 0))
        end]]--
        
        local SP = self.stomach:GetScale()
        self.obrsword_power:SetScale(SP)
 --self.obrsword_power:SetPosition(2221,1238, 0)
     
        -- self.obrsword_power.OnMouseButton = function(text, button, down, x, y, z, a, b, c)
        --     if button == MOUSEBUTTON_RIGHT and down then
        --         self.obrsword_power:FollowMouse()
        --     else
        --         self.obrsword_power:StopFollowMouse()
                
        --         self.obrsword_power:SetPosition(TheInput:GetScreenPosition())
        --                         --[[local x2, y2, z2 = self.obrsword_power:GetPosition():Get()
        -- print("能力值坐标是",x2, y2, z2)]] --
        --         local x1, y1, z1 = self.stomach:GetPosition():Get()
        --         local x2, y2, z2 = self.brain:GetPosition():Get()
        --         local x3, y3, z3 = self.heart:GetPosition():Get()
        --         print(x1, y1, z1)
        --         print(x2, y2, z2)
        --         print(x3, y3, z3)
               
        --     end
        -- end
    -- 监听事件 刷新数据
    self.inst:ListenForEvent("obrsword_powerdelta", function(inst, data)
        if self.obrsword_power ~= nil  then
        self.obrsword_power:SetPercent(self.owner.replica.obrsword_power:GetPercent(),
            self.owner.replica.obrsword_power:Max())
    end end, self.owner)
   end)
    self.owner:ListenForEvent("unequip", function(inst, data)

        if self.obrsword_power ~= nil then
            if not self.owner.replica.inventory:EquipHasTag("obrsword") then
            self.obrsword_power:Hide() end

        end

    end, self.owner)

    self.owner:ListenForEvent("equip", function(inst, data)
        -- 装备欧布圣剑才显示UI
        if self.obrsword_power ~= nil then
            if self.owner.replica.inventory:EquipHasTag("obrsword") then
                self.obrsword_power:Show()
            end
        end

    end, self.owner)

    self.obrsword_power:Hide()

    -- self.obrsword_power:SetPercent(self.owner.replica.obrsword_power:GetPercent(), self.owner.replica.obrsword_power:Max())
    --[[
	--死亡时候的隐藏
	local old_SetGhostMode = self.SetGhostMode
	function self:SetGhostMode(ghostmode,...)
		old_SetGhostMode(self,ghostmode,...)
		if ghostmode then		
			if self.obrsword_power ~= nil then 
				self.obrsword_power:Hide()
			end	
		else
			if self.obrsword_power ~= nil then
				self.obrsword_power:Show()
			end
		end
	end]] --
end
AddClassPostConstruct("widgets/statusdisplays", Add_obrsword_power)
